﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class frm_MainMenu : System.Web.UI.Page
{
    String[] arrRole =      { "1", "2", "3", "4" };
    String[] arrRoleCtr =   {"0,1,2", "0", "1", "2"};
    String[] arrCtr = {"btn_送り出し","btn_組合","btn_企業" };
    protected void Page_Load(object sender, EventArgs e)
    {
        btn_送り出し.Enabled = false;
        btn_組合.Enabled = false;
        btn_企業.Enabled = false;
        if (Session["役"] != null && Session["役"].ToString()=="1")
        {
            String strRole = Session["役"].ToString();
            setRoleToCtr(strRole);
        }
        else
        {
            Response.Redirect("frmD_Login.aspx");
        }
        int int_役 = Convert.ToInt32(Session["役"]);
        int int_送出し機関 = Convert.ToInt32(Session["送出し機関"]);
        int int_団体管理 = Convert.ToInt32(Session["団体管理"]);
        int int_実習実施機関 = Convert.ToInt32(Session["実習実施機関"]);
        if (int_役 == 3 && int_送出し機関 == 1)
        {
            btn_ログイン管理.Enabled = false;
        }
        if (int_役 == 3 && int_団体管理 == 1)
        {
            btn_ログイン管理.Enabled = false;
        }
        if (int_役 == 3 && int_実習実施機関 == 1)
        {
            btn_ログイン管理.Enabled = false;
        }

        if (!IsPostBack)
        {
            AppCode_Common.AddHistory(Page);

            if (Session["hobj"] != null)
                Session.Remove("hobj");
        }
    
    }
    private void setRoleToCtr(string role)
    {
        for(int rIndex = 0; rIndex < arrRole.Length; rIndex++)
        {
            if (arrRole[rIndex] == role)
            {
                String strRole = arrRoleCtr[rIndex];
                String[] Role = strRole.Split(',');
                for (int i = 0; i < Role.Length; i++)
                {
                    ImageButton btn = (ImageButton)this.FindControl(arrCtr[Convert.ToInt16(Role[i])]);
                    if (btn != null)
                    {
                        btn.Enabled = true;
                    }
                }
                break;
            }
        }
    }
    protected void btn_実習生_Click(object sender, EventArgs e)
    {
        Session["login"] = 0;
        //Response.Redirect("frm_Menu.aspx");
        Response.Redirect("frm_TraineeBasicInfo.aspx");
       
    }
    protected void btn_送り出し_Click(object sender, EventArgs e)
    {
        Session["login"] = 3;
        Response.Redirect("frm_MJointCompManager.aspx");
        //Response.Redirect("frm_MJointCompManager.aspx");
    }
    protected void btn_組合_Click(object sender, EventArgs e)
    {
        Session["login"] = 4;
        //Response.Redirect("frm_Menu.aspx");
        Response.Redirect("frm_MOrgManager.aspx");
    }
    protected void btn_企業_Click(object sender, EventArgs e)
    {
        Session["login"] = 1;
        Response.Redirect("frm_MRecCompManager.aspx");
    }
    protected void btn_ログイン管理_Click(object sender, ImageClickEventArgs e)
    {
        //Session["frm_MainMenu_flag"] = "1";
        Response.Redirect("frmD_CompLoginManager.aspx");
    }


    protected void lbtn_Logout_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("frmD_Login.aspx");
    }
}
